package com.mokairui.basic.demo2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Mokairui
 * @Description 客户端
 * @Since 2021/6/27
 */
public class Client {
    public static void main(String[] args) throws IOException {
        // 1.创建一个Socket对象请求服务端的链接
        Socket socket = new Socket("127.0.0.1", 9999);
        // 2.从Socket对象中获取一个字节输出流
        OutputStream os = socket.getOutputStream();
        // 3.把字节输出流包装成一个打印流
        PrintStream printStream = new PrintStream(os);
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请说：");
            printStream.println(scanner.nextLine());
            printStream.flush();
        }
    }
}
